package com.song.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author TonySong
 * @date 2024/6/15 0015
 * @time 11:18
 */
@Configuration
public class RabbitConfig {

      public static final String EXCHANGE_NAME = "topic-exchange";
      public static final String ROUTING_KEY = "orders.#";
      public static final String QUEUE_NAME = "orders";

      @Bean
      public TopicExchange topicExchange(){
          return new TopicExchange(EXCHANGE_NAME);
      }
      @Bean
      public Queue queue(){
          return new Queue(QUEUE_NAME);
      }

      @Bean
      public Binding  binding(){
          return BindingBuilder.bind(queue()).to(topicExchange()).with(ROUTING_KEY);
      }


      @Bean
      public MessageConverter messageConverter(){
          Jackson2JsonMessageConverter  converter = new Jackson2JsonMessageConverter();

          return converter;
      }

}
